Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Parsing of Multiline Argument Descriptions #527

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

shreya0204
Copy link

Fixes: #477

This pull request addresses a parsing error in the WP CLI handbook where multiline argument descriptions in the Utils\http_request() method were not being handled correctly. Previously, the parser failed to recognize , as a valid character that could indicate the continuation of an argument description onto a new line.

Changes Made:

Updated the conditional check in the parsing logic. Now, the parser recognizes both { and , characters as potential indicators of a multiline argument. This ensures that argument descriptions that continue after these characters are correctly parsed and included in the documentation.

@shreya0204 shreya0204 requested a review from a team as a code owner July 4, 2024 10:49
Copy link
Contributor

@wojtekn wojtekn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shreya0204 thanks for your contribution.

I think this change may need more work and possibly, another approach:

  • does the current approach cover multi-line comments that can occur inside {} block?
  • isn't it too greedy now? It uses a comma , to start a param block, and looks for } to reach the end?

bin/command.php Outdated
@@ -630,7 +630,9 @@ private static function parse_docblock( $docblock ) {
$key = key( $ret['parameters'][ $param_name ] );
reset( $ret['parameters'][ $param_name ] );
if ( ! empty( $ret['parameters'][ $param_name ][ $key ][2] )
&& '{' === substr( $ret['parameters'][ $param_name ][ $key ][2], -1 ) ) {
&&
in_array( substr( $ret['parameters'][ $param_name ][ $key ][2], -1 ), [ '{', ',' ], true )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will happen if a multi-line comment doesn't end with a comma?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @wojtekn

Thank you for your feedback and suggestion, I’ve updated the logic and refined the code based on it. I've also created a brief video to explain the updates, the assumptions made, and the approach taken.

Here’s the link to the video: Link

@shreya0204 shreya0204 requested a review from wojtekn July 23, 2024 06:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parsing issue with multiline argument description
2 participants